<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "quiz.Question" %>
<%
	String title = "";
	int type = Integer.parseInt((String)request.getParameter("type"));
	switch (type) {
	case Question.FITB:
		title = "New Fill in the Blank Question";
		break;
	case Question.MC:
		title = "Multiple Choice Question";
		break;
	case Question.PICTURE:
		title = "Picture Question";
		break;
	case Question.QR:
		title = "Free Response Question";
		break;
	}
	
	String pageTitle = title + " | Quizzard";
%>
<jsp:include page="templates/header.jsp" flush="true">
	<jsp:param value = "<%= pageTitle %>" name = "title" />
</jsp:include>
<jsp:include page="templates/title_bar.jsp" flush = "true">
	<jsp:param value = "<%= title %>" name = "title" />
</jsp:include>
<div id = "content">
<div class = "center">
<%
	int numAnswers = Integer.parseInt((String)request.getParameter("numberAnswers"));
	int quizId = Integer.parseInt((String)request.getParameter("quizID"));

	String error = (String)request.getAttribute("error");
	if (error != null) {
		out.println("<div id = 'error'>"+error+"</div>");
	}
	
	String answers = "";
	
	for (int i = 1; i <= numAnswers; i++) {
		switch(type) {
		case Question.MC:
			answers += "<p>Answer Choice "+i+": <input type = \"text\" name = \"answer"+i+"\" /> Correct? <input type = \"checkbox\" name = \"answer"+i+"correct\" /></p>";
			break;
		case Question.PICTURE:
		case Question.FITB:
		case Question.QR:
			answers += "<p>Answer "+i+": <textarea name = \"answer"+i+"\"></textarea>";
			break;
		}
	}
%>
<div class = "section_title">Add a new question</div>
<form method = "post" action = "CreateQuestion">
<div class = "bottom_border">
<p><label for = "question">Question </label>
<% if (type == Question.FITB) { %>
Before blank: <input type = "text" name = "before" /> After blank: <input type = "text" name = "after" />
<% } else if (type == Question.PICTURE) { %>
Picture <input type = "text" name = "picture">
<% } else { %>
<input type = "text" name = "question" />
<% } %>
</p>
<p><label for = "weight">Weight </label><input type = "text" name = "weight" value = "1" /></p>
<!--<p><label for = "time">Maximum Time (Less than or equal to 0 for no limit)</label><input type = "text" name = "time" value = "0" /></p>-->
 <input type = "hidden" name = "numberAnswers" value = "<%= numAnswers %>" />
<input type = "hidden" name = "type" value = "<%= type %>" />
<input type = "hidden" name = "quizID" value = "<%= quizId %>" />
</div>
<div class = "section_title">Answers</div>
<div class = "answers"><%= answers %></div>
<input type = "submit" value = "Add Question" class = "btn" />
</form>
</div>
</div>
<jsp:include page="templates/footer.jsp" flush="true" />